package com.rbac.web.db;

import com.baomidou.mybatisplus.annotation.TableName;
import com.rbac.web.model.RolePermission;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * @author gengaoliu
 */
@Data
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@TableName("role_permission")
public class RolePermissionDO extends BaseDO {

  private Integer roleId;
  private Integer permissionId;

  public static RolePermissionDO from(RolePermission rolePermission) {
    return RolePermissionDO.builder().id(rolePermission.getId())
        .createTime(rolePermission.getCreatedTime()).roleId(rolePermission.getRoleId())
        .permissionId(rolePermission.getPermissionId()).build();
  }

  public RolePermission to() {
    return RolePermission.builder().id(getId()).createdTime(getCreateTime()).roleId(getRoleId())
        .permissionId(getPermissionId()).build();
  }
}
